using System;
/*
 *  Copyright (C) 2007 Noury Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using WebForms=System.Web.UI.WebControls;

namespace Salamanca.DataActivities.UI.Web.WebControls
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Interface implemented by a <see cref="CompositeQuestion" /> provider.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public interface ICompositeQuestionProvider
    {

        /// <summary>Gets the questions.</summary>
        CompositeQuestion GetQuestions();
    }

    //public class CompositeQuestion:
    //    Salamanca.DataActivities.UI.CompositeQuestion
    //{
    //    public CompositeQuestion(IDictionary<string, IQuestion> innerQuestions):
    //        base(innerQuestions)
    //    {
    //    }

    //    public override void OnInitialized(QuestionEventArgs e)
    //    {
    //        base.OnInitialized(e);
    //    }

    //    public override void OnTerminated(QuestionEventArgs e)
    //    {
    //        base.OnTerminated(e);
    //    }
    //}



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Implementation of a <see cref="ICompositeQuestionProvider" />.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public class CompositeQuestionProvider
    {

        /// <summary>Initializes a new <see cref="CompositeQuestionProvider" /> instance.</summary>
        public CompositeQuestionProvider()
        {
            _Path=HttpContext.Current.Request.Path;
        }

        /// <summary>Initializes a new <see cref="CompositeQuestionProvider" /> instance.</summary>
        public CompositeQuestionProvider(string path)
        {
            _Path=path;
        }

        /// <summary>Gets the questions.</summary>
        public CompositeQuestion GetQuestions(IActivityController controller)
        {
            if (HttpContext.Current.Server.MapPath(HttpContext.Current.Request.Path)!=HttpContext.Current.Server.MapPath(_Path))
            {
                //ActivityControllersSessionStack.Instance.Push(controller);
                HttpContext.Current.Response.Redirect(_Path);
            }

            CompositeQuestion ret=((ICompositeQuestionProvider)HttpContext.Current.Handler).GetQuestions();
            //ret.Terminated+=new EventHandler<QuestionEventArgs>(
            //    delegate {
            //        ActivityControllersSessionStack.Instance.Pop();
            //    }
            //);
            return ret;
        }

        private string _Path;
    }
}
